package org.lease.web.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.lease.common.result.Result;
import org.lease.model.entity.LabelInfo;
import org.lease.model.enums.ItemType;
import org.lease.service.LabelInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "标签信息管理")
@RestController
@RequestMapping("/admin/label")
public class LabelInfoController {
    @Autowired
    private LabelInfoService labelInfoService;

    @Operation(summary = "根据分类查询标签信息")
    @GetMapping("/list")
    public Result<List<LabelInfo>> listByType(@RequestParam(required = false) ItemType itemType) {
        List<LabelInfo> list = labelInfoService.listByType(itemType);
        return Result.success(list);
    }

    @Operation(summary = "保存或更新标签信息")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody LabelInfo labelInfo) {
        labelInfoService.saveOrUpdate(labelInfo);
        return Result.success();
    }
}
